/*
 * 存款利率计算器v3.0（8分）
 *
 * v1.0，见：02_week02/3_Deposit_Interest_Rate_Calculator_v1.c
 * v2.0，见：Weekly_Programming_Test/04-week04/2_Deposit_Interest_Rate_Calculator_v2.c
 */

#include <stdio.h>
#include <math.h>

#define RATE_LENGTH 5

int main() {
	setbuf(stdout, NULL);

	// NOTE: Variable declaration
	int n;
	double rate[RATE_LENGTH] = {0.0225, 0.0243, 0.0270, 0.0228, 0.0300}, capital, deposit;

	// 计息方式标记
	char flag;


	// NOTE: Inputs
	printf("Input rate, n, capital:");
	scanf("%lf,%d", &capital, &n);

	// 获取计息方式标记
	printf("Compound interest (Y/N)?");
	scanf(" %c", &flag);


	// NOTE: Process
	// 判断年份是否正确
	if (n == 1 || n == 2 || n == 3 || n == 5 || n == 8) {
		// 判断计息方式
		if (flag == 'Y' || flag == 'y') {
			// 根据存款期限计息
			switch (n) {
				case 1:
					printf("rate = %.4f, deposit = %.4f\n", rate[0], capital * pow(1 + rate[0], n));
					break;
				case 2:
					printf("rate = %.4f, deposit = %.4f\n", rate[1], capital * pow(1 + rate[1], n));
					break;
				case 3:
					printf("rate = %.4f, deposit = %.4f\n", rate[2], capital * pow(1 + rate[2], n));
					break;
				case 5:
					printf("rate = %.4f, deposit = %.4f\n", rate[3], capital * pow(1 + rate[3], n));
					break;
				case 8:
					printf("rate = %.4f, deposit = %.4f\n", rate[4], capital * pow(1 + rate[4], n));
					break;
			}
		} else if (flag == 'N' || flag == 'n') {
			// 根据存款期限计息
			switch (n) {
				case 1:
					printf("rate = %.4f, deposit = %.4f\n", rate[0], capital * (1 + rate[0] * n));
					break;
				case 2:
					printf("rate = %.4f, deposit = %.4f\n", rate[1], capital * (1 + rate[1] * n));
					break;
				case 3:
					printf("rate = %.4f, deposit = %.4f\n", rate[2], capital * (1 + rate[2] * n));
					break;
				case 5:
					printf("rate = %.4f, deposit = %.4f\n", rate[3], capital * (1 + rate[3] * n));
					break;
				case 8:
					printf("rate = %.4f, deposit = %.4f\n", rate[4], capital * (1 + rate[4] * n));
					break;
			}
		}
	} else {
		// 年份输入错误，给出错误信息
		printf("Error year!\n");
	}


	// NOTE: Outputs

	// NOTE: Ending
	return 0;
}